//
//  JudgeForProductViewController.m
//  ChunLaiZhuangClient
//
//  Created by zzs on 16/4/16.
//  Copyright © 2016年 CLZ. All rights reserved.
//

#import "JudgeForProductViewController.h"

@interface JudgeForProductViewController ()
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UIImageView *productImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *totalLabel;
@property (weak, nonatomic) IBOutlet UITextView *judgeTF;
@property (weak, nonatomic) IBOutlet UILabel *placeLabel;
- (IBAction)toJudgeAction:(id)sender;

@end

@implementation JudgeForProductViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.judgeTF.layer.cornerRadius=4;
    [self setNaviTitle:@"评价"];
    [self setNaviLeftButton:@""];
    [self.productImageView sd_setImageWithURL:[NSURL URLWithString:self.detailModel.image] placeholderImage:nil];
    self.nameLabel.text=self.detailModel.name;
    self.totalLabel.text=self.detailModel.total;
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.bgView addGestureRecognizer:tap];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)toJudgeAction:(id)sender {
    [self.judgeTF resignFirstResponder];
    if (self.judgeTF.text.length==0) {
        [[LKDHud shareHud] showtip:@"评论内容不能为空"];
        return;
    }
    [ApiClient addReviewOrder_product_id:self.detailModel.order_product_id product_id:self.detailModel.product_id review:self.judgeTF.text rating:@"5" didFinishLoaded:^(KXJson *json, NSString *path) {
         [[LKDHud shareHud] hideLoadingView];
        if ([json getIntForKey:@"status"]==1) {
           [[LKDHud shareHud] showtip:@"评论成功!"];
            [self performSelector:@selector(popView) withObject:nil afterDelay:0.5];
           
        }else{
            [[LKDHud shareHud] showtip:[json getStringForKey:@"message"]];
        }
       
           
    } didFailLoaded:^(NSError *error, NSString *path) {
    
    }];
}
-(void)popView{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)tapAction:(UITapGestureRecognizer*)tap{
     [self.judgeTF resignFirstResponder];
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    NSString *resultingString = [textView.text stringByReplacingCharactersInRange: range withString: text];
    if (resultingString.length==0) {
        _placeLabel.hidden=NO;
    }else{
        _placeLabel.hidden=YES;
    }
       return YES;
}
- (void)textViewDidChange:(UITextView *)textView{
    
    if ([textView.text length] == 0) {
        _placeLabel.hidden=NO;
    }else{
        _placeLabel.hidden=YES;
    }
}

@end
